package epam.marchenko.library.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Table(name = "incomes")
@NamedQueries({
	@NamedQuery(name = "IncomeRecord.findAll", query = "SELECT r FROM IncomeRecord r")
})
public class IncomeRecord implements Serializable {

	private static final long serialVersionUID = 1L;
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", nullable = false)
	private int id;
	@OneToOne()
	@JoinColumn(name = "order_id")
	private OutcomeRecord outcome;
	@Temporal(value = TemporalType.DATE)
	@Column(name = "real_return_date")
	@DateTimeFormat(pattern = "dd/MM/yyyy")
	private Date realReturnDate;
	@Column(name = "delay_fine")
	private Double delayFine;
	@Column(name = "damage_fine")
	private Double damageFine;
	
	public IncomeRecord() {}
	

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getRealReturnDate() {
		return realReturnDate;
	}

	public OutcomeRecord getOutcome() {
		return outcome;
	}

	public void setOutcome(OutcomeRecord outcome) {
		this.outcome = outcome;
	}

	public void setRealReturnDate(Date realReturnDate) {
		this.realReturnDate = realReturnDate;
	}
	
	public Double getDelayFine() {
		return delayFine;
	}


	public void setDelayFine(Double delayFine) {
		this.delayFine = delayFine;
	}


	public Double getDamageFine() {
		return damageFine;
	}


	public void setDamageFine(Double damageFine) {
		this.damageFine = damageFine;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((damageFine == null) ? 0 : damageFine.hashCode());
		result = prime * result
				+ ((delayFine == null) ? 0 : delayFine.hashCode());
		result = prime * result + id;
		result = prime * result + ((outcome == null) ? 0 : outcome.hashCode());
		result = prime * result
				+ ((realReturnDate == null) ? 0 : realReturnDate.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		IncomeRecord other = (IncomeRecord) obj;
		if (damageFine == null) {
			if (other.damageFine != null)
				return false;
		} else if (!damageFine.equals(other.damageFine))
			return false;
		if (delayFine == null) {
			if (other.delayFine != null)
				return false;
		} else if (!delayFine.equals(other.delayFine))
			return false;
		if (id != other.id)
			return false;
		if (outcome == null) {
			if (other.outcome != null)
				return false;
		} else if (!outcome.equals(other.outcome))
			return false;
		if (realReturnDate == null) {
			if (other.realReturnDate != null)
				return false;
		} else if (!realReturnDate.equals(other.realReturnDate))
			return false;
		return true;
	}


	@Override
	public String toString() {
		return "IR " + id;
	}	

}
